import Tkinter
import Pmw
import sys

title = 'Constraints'

class OTabList:
    def __init__(self, parent, list, label):
    # Create the ScrolledListBox.
    self.box = Pmw.ScrolledListBox(parent,
        items=list,
        labelpos='nw',
        label_text=label,
        listbox_height = 6,
        #selectioncommand=self.selectionCommand,
        dblclickcommand=self.getSelected,
        usehullsize = 1,
        hull_width = 200,
        hull_height = 200,
    )

    # Pack this last so that the buttons do not get shrunk when
    # the window is resized.
    self.box.pack(fill = 'both', expand = 1, padx = 5, pady = 5)

    def sethscrollmode(self, tag):
    self.box.configure(hscrollmode = tag)

    def setvscrollmode(self, tag):
    self.box.configure(vscrollmode = tag)

    def getSelected(self):
    sels = self.box.getcurselection()
    if len(sels) != 0:
        conID = -1
        for i in range(len(self.hierarchy)):
            if self.hierarchy[i] == sels[0]:
                conID = i
        
        if conID != None:
            self.update()
            self.demoteConstraint(conID)
            self.redraw()

    def showYView(self):
        print self.box.yview()

    def pageDown(self):
        self.box.yview('up', 1, 'page')

    def centerPage(self):
        top, bottom = self.box.yview()
        size = bottom - top
        middle = 0.5 - size / 2
        self.box.yview('moveto', middle)

######################################################################

# Create demo in root window for testing.
if __name__ == '__main__':
    root = Tkinter.Tk()
    Pmw.initialise(root)
    root.title(title)

    exitButton = Tkinter.Button(root, text = 'Close', command = root.destroy)
    exitButton.pack(side = 'bottom')
    widget = OTabList(root, ('Max','Dep','NoCoda'), 'Constraints')
    root.mainloop()
